import { createRouter, createWebHashHistory } from "vue-router";
import routes from "./routes.js";
import VConsole from "vconsole";
import { getUrlParam, getUrlKey } from "../utils/help.js";
const whitePaths = [];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
var vConsole = new VConsole();

// 全局守卫：登录拦截 本地没有存token,请重新登录
router.beforeEach((to, from, next) => {
  // let isTest = localStorage.getItem("isTest");
  let userToken = sessionStorage.getItem("token");

  if (userToken || !whitePaths.includes(to.name)) {
    next();
  } else if (!userToken) {
    next("/login");
  }

});

export default router;
